home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / SETUP / US / CBUILDER / DATA.Z / WINCRYPT.H < prev    next >
C/C++ Source or Header  |  1997-02-13  |  13KB  |  568 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. //  File:       wincrypt.h
  7. //
  8. //  Contents:   Cryptographic API Prototypes and Definitions
  9. //
  10. //----------------------------------------------------------------------------
  11.  
  12. #ifndef __WINCRYPT_H__
  13. #define __WINCRYPT_H__
  14. #pragma option -b
  15.  
  16. #if(_WIN32_WINNT >= 0x0400)
  17.  
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21.  
  22. #ifdef __BORLANDC__
  23. #pragma option -b.
  24.   #include <pshpack8.h>
  25. #pragma option -b
  26. #endif
  27.  
  28. //
  29. // Algorithm IDs and Flags
  30. //
  31.  
  32. // ALG_ID crackers
  33. #define GET_ALG_CLASS(x)                (x & (7 << 13))
  34. #define GET_ALG_TYPE(x)                 (x & (15 << 9))
  35. #define GET_ALG_SID(x)                  (x & (511))
  36.  
  37. // Algorithm classes
  38. #define ALG_CLASS_ANY                   (0)
  39. #define ALG_CLASS_SIGNATURE             (1 << 13)
  40. #define ALG_CLASS_MSG_ENCRYPT           (2 << 13)
  41. #define ALG_CLASS_DATA_ENCRYPT          (3 << 13)
  42. #define ALG_CLASS_HASH                  (4 << 13)
  43. #define ALG_CLASS_KEY_EXCHANGE          (5 << 13)
  44.  
  45. // Algorithm types
  46. #define ALG_TYPE_ANY                    (0)
  47. #define ALG_TYPE_DSS                    (1 << 9)
  48. #define ALG_TYPE_RSA                    (2 << 9)
  49. #define ALG_TYPE_BLOCK                  (3 << 9)
  50. #define ALG_TYPE_STREAM                 (4 << 9)
  51.  
  52. // Generic sub-ids
  53. #define ALG_SID_ANY                     (0)
  54.  
  55. // Some RSA sub-ids
  56. #define ALG_SID_RSA_ANY                 0
  57. #define ALG_SID_RSA_PKCS                1
  58. #define ALG_SID_RSA_MSATWORK            2
  59. #define ALG_SID_RSA_ENTRUST             3
  60. #define ALG_SID_RSA_PGP                 4
  61.  
  62. // Some DSS sub-ids
  63. //
  64. #define ALG_SID_DSS_ANY                 0
  65. #define ALG_SID_DSS_PKCS                1
  66. #define ALG_SID_DSS_DMS                 2
  67.  
  68. // Block cipher sub ids
  69. // DES sub_ids
  70. #define ALG_SID_DES                     1
  71. #define ALG_SID_3DES            3
  72. #define ALG_SID_DESX            4
  73. #define ALG_SID_IDEA            5
  74. #define ALG_SID_CAST            6
  75. #define ALG_SID_SAFERSK64        7
  76. #define ALD_SID_SAFERSK128        8
  77.  
  78. // KP_MODE
  79. #define CRYPT_MODE_CBCI            6    // ANSI CBC Interleaved
  80. #define CRYPT_MODE_CFBP            7    // ANSI CFB Pipelined
  81. #define CRYPT_MODE_OFBP            8    // ANSI OFB Pipelined
  82. #define CRYPT_MODE_CBCOFM        9    // ANSI CBC + OF Masking
  83. #define CRYPT_MODE_CBCOFMI        10    // ANSI CBC + OFM Interleaved
  84.  
  85. // RC2 sub-ids
  86. #define ALG_SID_RC2                     2
  87.  
  88. // Stream cipher sub-ids
  89. #define ALG_SID_RC4                     1
  90. #define ALG_SID_SEAL                    2
  91.  
  92. // Hash sub ids
  93. #define ALG_SID_MD2                     1
  94. #define ALG_SID_MD4                     2
  95. #define ALG_SID_MD5                     3
  96. #define ALG_SID_SHA                     4
  97. #define ALG_SID_MAC                     5
  98. #define ALG_SID_RIPEMD            6
  99. #define ALG_SID_RIPEMD160        7
  100. #define ALG_SID_SSL3SHAMD5        8
  101.  
  102.  
  103. // Our silly example sub-id
  104. #define ALG_SID_EXAMPLE                 80
  105.  
  106. #ifndef ALGIDDEF
  107. #define ALGIDDEF
  108. typedef unsigned int ALG_ID;
  109. #endif
  110.  
  111. // algorithm identifier definitions
  112. #define CALG_MD2        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD2)
  113. #define CALG_MD4        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD4)
  114. #define CALG_MD5        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MD5)
  115. #define CALG_SHA        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA)
  116. #define CALG_MAC        (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_MAC)
  117. #define CALG_RSA_SIGN   (ALG_CLASS_SIGNATURE | ALG_TYPE_RSA | ALG_SID_RSA_ANY)
  118. #define CALG_DSS_SIGN   (ALG_CLASS_SIGNATURE | ALG_TYPE_DSS | ALG_SID_DSS_ANY)
  119. #define CALG_RSA_KEYX   (ALG_CLASS_KEY_EXCHANGE|ALG_TYPE_RSA|ALG_SID_RSA_ANY)
  120. #define CALG_DES        (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_DES)
  121. #define CALG_RC2        (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_BLOCK|ALG_SID_RC2)
  122. #define CALG_RC4        (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_RC4)
  123. #define CALG_SEAL       (ALG_CLASS_DATA_ENCRYPT|ALG_TYPE_STREAM|ALG_SID_SEAL)
  124.  
  125. typedef struct _VTableProvStruc {
  126.     DWORD   Version;
  127.     FARPROC FuncVerifyImage;
  128.     FARPROC FuncReturnhWnd;
  129. } VTableProvStruc, *PVTableProvStruc;
  130.  
  131. typedef unsigned long HCRYPTPROV;
  132. typedef unsigned long HCRYPTKEY;
  133. typedef unsigned long HCRYPTHASH;
  134.  
  135. // dwFlags definitions for CryptAquireContext
  136. #define CRYPT_VERIFYCONTEXT     0xF0000000
  137. #define CRYPT_NEWKEYSET         0x8
  138. #define CRYPT_DELETEKEYSET      0x10
  139.  
  140. // dwFlag definitions for CryptGenKey
  141. #define CRYPT_EXPORTABLE        0x00000001
  142. #define CRYPT_USER_PROTECTED    0x00000002
  143. #define CRYPT_CREATE_SALT       0x00000004
  144. #define CRYPT_UPDATE_KEY        0x00000008
  145.  
  146. // exported key blob definitions
  147. #define SIMPLEBLOB              0x1
  148. #define PUBLICKEYBLOB           0x6
  149. #define PRIVATEKEYBLOB          0x7
  150.  
  151. #define AT_KEYEXCHANGE          1
  152. #define AT_SIGNATURE            2
  153.  
  154. #define CRYPT_USERDATA          1
  155.  
  156. // dwParam
  157. #define KP_IV                   1       // Initialization vector
  158. #define KP_SALT                 2       // Salt value
  159. #define KP_PADDING              3       // Padding values
  160. #define KP_MODE                 4       // Mode of the cipher
  161. #define KP_MODE_BITS            5       // Number of bits to feedback
  162. #define KP_PERMISSIONS          6       // Key permissions DWORD
  163. #define KP_ALGID                7       // Key algorithm
  164. #define KP_BLOCKLEN             8       // Block size of the cipher
  165.  
  166. // KP_PADDING
  167. #define PKCS5_PADDING           1       // PKCS 5 (sec 6.2) padding method
  168.  
  169. // KP_MODE
  170. #define CRYPT_MODE_CBC          1       // Cipher block chaining
  171. #define CRYPT_MODE_ECB          2       // Electronic code book
  172. #define CRYPT_MODE_OFB          3       // Output feedback mode
  173. #define CRYPT_MODE_CFB          4       // Cipher feedback mode
  174. #define CRYPT_MODE_CTS          5       // Ciphertext stealing mode
  175.  
  176. // KP_PERMISSIONS
  177. #define CRYPT_ENCRYPT           0x0001  // Allow encryption
  178. #define CRYPT_DECRYPT           0x0002  // Allow decryption
  179. #define CRYPT_EXPORT            0x0004  // Allow key to be exported
  180. #define CRYPT_READ              0x0008  // Allow parameters to be read
  181. #define CRYPT_WRITE             0x0010  // Allow parameters to be set
  182. #define CRYPT_MAC               0x0020  // Allow MACs to be used with key
  183.  
  184. #define HP_ALGID                0x0001  // Hash algorithm
  185. #define HP_HASHVAL              0x0002  // Hash value
  186. #define HP_HASHSIZE             0x0004  // Hash value size
  187.  
  188.  
  189. #define CRYPT_FAILED            FALSE
  190. #define CRYPT_SUCCEED           TRUE
  191.  
  192. #define RCRYPT_SUCCEEDED(rt)     ((rt) == CRYPT_SUCCEED)
  193. #define RCRYPT_FAILED(rt)        ((rt) == CRYPT_FAILED)
  194.  
  195. //
  196. // CryptGetProvParam
  197. //
  198. #define PP_ENUMALGS             1
  199. #define PP_ENUMCONTAINERS       2
  200. #define PP_IMPTYPE              3
  201. #define PP_NAME                 4
  202. #define PP_VERSION              5
  203. #define PP_CONTAINER            6
  204.  
  205. #define CRYPT_FIRST             1
  206. #define CRYPT_NEXT              2
  207.  
  208. #define CRYPT_IMPL_HARDWARE     1
  209. #define CRYPT_IMPL_SOFTWARE     2
  210. #define CRYPT_IMPL_MIXED        3
  211. #define CRYPT_IMPL_UNKNOWN      4
  212.  
  213. //
  214. // CryptSetProvParam
  215. //
  216. #define PP_CLIENT_HWND          1
  217.  
  218. #define PROV_RSA_FULL           1
  219. #define PROV_RSA_SIG            2
  220. #define PROV_DSS                3
  221. #define PROV_FORTEZZA           4
  222. #define PROV_MS_EXCHANGE        5
  223. #define PROV_SSL                6
  224.  
  225. //
  226. //STT defined Providers
  227. //
  228. #define PROV_STT_MER                    7
  229. #define PROV_STT_ACQ                    8
  230. #define PROV_STT_BRND                   9
  231. #define PROV_STT_ROOT                   10
  232. #define PROV_STT_ISS                    11
  233.  
  234.  
  235. #define MS_DEF_PROV_A       "Microsoft Base Cryptographic Provider v1.0"
  236. #define MS_DEF_PROV_W       L"Microsoft Base Cryptographic Provider v1.0"
  237. #ifdef UNICODE
  238. #define MS_DEF_PROV         MS_DEF_PROV_W
  239. #else
  240. #define MS_DEF_PROV         MS_DEF_PROV_A
  241. #endif
  242.  
  243. #define MAXUIDLEN               64
  244.  
  245. #define CUR_BLOB_VERSION        2
  246.  
  247. typedef struct _PROV_ENUMALGS {
  248.     ALG_ID    aiAlgid;
  249.     DWORD     dwBitLen;
  250.     DWORD     dwNameLen;
  251.     CHAR      szName[20];
  252. } PROV_ENUMALGS;
  253.  
  254.  
  255. typedef struct _PUBLICKEYSTRUC {
  256.